// run: $exec < input
#include <iostream>
#include <cstring>
#include <utility>
#include <queue>

struct pos { int x, y; };

bool operator==(pos const & a, pos const & b)
{
	return a.x == b.x && a.y == b.y;
}

typedef std::pair<pos, int> state;

int const opt[8][2] = {{-1, -2}, {1, -2}, {2, -1}, {2, 1},
						{1, 2}, {-1, 2}, {-2, 1}, {-2, -1}};
int const maxl = 303;
bool visited[maxl][maxl];
pos start, end;
int l;

bool inrange(pos const & a)
{
	return 0 <= a.x && a.x < l && 0 <= a.y && a.y < l;
}

int main()
{
	int T;
	std::cin >> T;
	while (T--) {
		std::memset(visited, 0, sizeof(visited));
		std::cin >> l;
		std::cin >> start.x >> start.y;
		std::cin >> end.x >> end.y;

		std::queue<state> q;
		q.push(std::make_pair(start, 0));
		visited[start.x][start.y] = true;
		while (!q.empty()) {
			state now = q.front();
			q.pop();
			if (now.first == end) {
				std::cout << now.second << '\n';
				break;
			}
			state tmp = now; tmp.second++;
			for (int i = 0; i < 8; i++) {
				tmp.first.x = now.first.x + opt[i][0];
				tmp.first.y = now.first.y + opt[i][1];
				if (inrange(tmp.first) && !visited[tmp.first.x][tmp.first.y]) {
					q.push(tmp);
					visited[tmp.first.x][tmp.first.y] = true;
				}
			}
		}
	}
}

